import 'package:flutter_admin/utils/utils.dart';

class StoresRequisition {
  String? id;
  String? number;
  String? purpose;
  String? workshopId;
  String? workshopName;
  String? userId;
  String? userName;
  String? requisitionDate;
  String? dateStart;
  String? dateEnd;

  StoresRequisition({
    this.id,
    this.number,
    this.purpose,
    this.workshopId,
    this.workshopName,
    this.userId,
    this.userName,
    this.requisitionDate,
    this.dateStart,
    this.dateEnd,
  });

  @override
  String toString() {
    return '''StoresRequisition{
      id: $id,
      number: $number,
      purpose: $purpose,
      workshopId: $workshopId,
      workshopName: $workshopName,
      userId: $userId,
      userName: $userName,
      requisitionDate: $requisitionDate,
    }''';
  }

  factory StoresRequisition.fromMap(Map<String, dynamic> map) {
    return new StoresRequisition(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      number: map['number'] != false ? map['number'].toString() as String? : "",
      purpose:
          map['purpose'] != false ? map['purpose'].toString() as String? : "",
      workshopId: map['workshop_id'] != false
          ? map['workshop_id'][0].toString() as String?
          : "",
      workshopName: map['workshop_id'] != false
          ? map['workshop_id'][1].toString() as String?
          : "",
      userId: map['user_id'] != false
          ? map['user_id'][0].toString() as String?
          : "",
      userName: map['user_id'] != false
          ? map['user_id'][1].toString() as String?
          : "",
      requisitionDate: map['get_date'] != false
          ? map['get_date'].toString() as String?
          : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'number': this.number,
      'purpose': this.purpose,
      'workshopId': this.workshopId,
      'workshopName': this.workshopName,
      'userId': this.userId,
      'userName': this.userName,
      'requisitionDate': this.requisitionDate,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    // ignore: unnecessary_cast
    List list = [
      if (this.workshopId != null && this.workshopId != '')
        ['workshop_id', '=', int.parse(this.workshopId!)],
      if (this.dateStart != null && this.dateStart != '')
        [
          'get_date',
          '>=',
          this.dateStart
        ],
      if (this.dateEnd != null && this.dateEnd != '')
        [
          'get_date',
          '<=',
          this.dateEnd!
        ],
    ] as List;
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'number': this.number,
      'purpose': this.purpose,
      'workshop_id': int.parse(this.workshopId!),
      'user_id': int.parse(this.userId!),
      'get_date': this.requisitionDate,
    } as Map<String, dynamic>;
  }
}
